#include<stack>
using namespace std;
class MyQueue {
public:
    stack<int> inq, outq;
    MyQueue() {

    }

    void push(int x) {
        inq.push(x);
    }

    int pop() {
        if (inq.empty())
            exit(0);
        int in_size = inq.size();
        for (int i = 0; i < in_size - 1; ++i) {
            outq.push(inq.top());
            inq.pop();
        }
        int pnum = inq.top();
        inq.pop();
        int out_size = outq.size();
        for (int i = 0; i < out_size; ++i) {
            inq.push(outq.top());
            outq.pop();
        }
        return pnum;
    }

    int peek() {
        if (inq.empty())
            exit(0);
        int in_size = inq.size();
        for (int i = 0; i < in_size - 1; ++i) {
            outq.push(inq.top());
            inq.pop();
        }
        int pnum = inq.top();
        outq.push(inq.top());
        inq.pop();
        int out_size = outq.size();
        for (int i = 0; i < out_size; ++i) {
            inq.push(outq.top());
            outq.pop();
        }
        return pnum;
    }

    bool empty() {
        return inq.empty();
    }
};
